import 'package:core_package/core_package.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_unionad/model/recharge_order_model.dart';
import 'package:flutter_app_unionad/request/facility_request.dart';
import 'package:flutter_app_unionad/ui/partnership/facility_list_page.dart';
import 'package:flutter_app_unionad/ui/user_center/widget/recharge_item_widget.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';

//资金明细 充值
class FinancialDetailThreeWidget extends StatefulWidget {
  final int? userID;

  const FinancialDetailThreeWidget({Key? key, this.userID}) : super(key: key);

  @override
  _FinancialDetailThreeWidgetState createState() => _FinancialDetailThreeWidgetState();
}

class _FinancialDetailThreeWidgetState extends State<FinancialDetailThreeWidget> with BaseRefreshDelegate {
  List<RechargeOrderModel> ?dataSource;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    reloadData(pageSize);
  }

  @override
  Future reloadData(int page) async {
    // TODO: implement reloadData
    final future = await FacilityRequest.getOrderList(pageNum: page);
    if (future != null) {
      if (dataSource == null) dataSource = [];
      if (page == 0) dataSource?.clear();
      dataSource?.addAll(future);
    }
    if (mounted) setState(() {});

    endRefresh((future != null) && future.length > 20);
    return future;
  }

  @override
  Widget build(BuildContext context) {
    print(dataSource);
    if (dataSource == null) {
      return ProgressDialog.showFirstLoading();
    }
    if (dataSource!.length == 0) {
      return Center(child: EmptyWidget());
    }
    return buildRefreshDelegate(context,
        slier: ListView.builder(
          padding: EdgeInsets.zero,
          itemCount: dataSource!.length,
          itemBuilder: (ctx, index) {
            return ExchangeItemWidget(
              isRecharge: true,
              model: dataSource![index],
            );
          },
        ));
  }
}
